unit New;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ExtCtrls, ComCtrls, ExtDlgs;

type
  TfNew = class(TForm)
    Label4: TLabel;
    Edit3: TEdit;
    Label2: TLabel;
    Label3: TLabel;
    Label5: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    UpDown1: TUpDown;
    UpDown2: TUpDown;
    Image1: TImage;
    BitBtn2: TBitBtn;
    BitBtn1: TBitBtn;
    Edit4: TEdit;
    SpeedButton1: TSpeedButton;
    OPD: TOpenPictureDialog;
    Label6: TLabel;
    BitBtn3: TBitBtn;
    ComboBox1: TRadioGroup;
    procedure BitBtn1Click(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    DCC: Word;
  end;

var
  fNew: TfNew;

implementation

uses Main, Tox, uImage2, uUtils, UMapCommon, uAdvMap;

{$R *.dfm}

procedure TfNew.BitBtn1Click(Sender: TObject);
var
  X, Y: Word;
begin
  with fMain do
  begin
    EmptyMap;
    CurrentFileName := 'New.map';
    SZ.X := StrToInt(Edit1.Text);
    SZ.Y := StrToInt(Edit2.Text);
    MapName := Trim(Edit3.Text);

    CP := Point(1, 1);
    DungeonTileset := Trim(Edit4.Text);
    LayerID := 0;
    fMain.ComboBox1Change(Sender);
    RefreshMap;
    for Y := 0 to SZ.Y - 1 do
      for X := 0 to SZ.X - 1 do
      begin
        Layer[lyMap][X, Y] := DCC;
        Layer[lyDcr][X, Y] := 0;
        Layer[lyObj][X, Y] := 0;
        Layer[lyItm][X, Y] := 0;
      end;
    DisplayMap;
  end;
end;

procedure TfNew.SpeedButton1Click(Sender: TObject);
var
  S: string;
  I: Integer;
begin
  if OPD.Execute then
  begin
    DCC := 0;
    I := Pos('Data', OPD.FileName);
    S := Copy(OPD.FileName, I, Length(OPD.FileName));
//    ShowMessage(S);
    Edit4.Text := S;
    fMain.DungeonTileset := Trim(Edit4.Text);
    Image1.Canvas.Draw(0, 0, GetImage(Path + Trim(Edit4.Text), DCC));
  end;
end;

procedure TfNew.BitBtn2Click(Sender: TObject);
begin
  fTox.ShowModal;
end;

procedure TfNew.FormShow(Sender: TObject);
begin
  Image1.Canvas.Draw(0, 0, GetImage(Path + Trim(Edit4.Text), 0));
end;

procedure TfNew.ComboBox1Change(Sender: TObject);
var
  P: Word;
begin
  case ComboBox1.ItemIndex of
    0: P := 32;
    1: P := 64;
    2: P := 128;
    3: P := 256;
    4: P := 512;
  end;
  UpDown1.Position := P;
  UpDown2.Position := P;
end;

end.
